package com.lk.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * @author lk
 *
 * @param <T>
 * @description  通用工具类
 */
@Data
@AllArgsConstructor
public class Result<T> implements Serializable {

    private Integer code;
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    private Result() {
        throw new IllegalStateException("Utility class");
    }

    public static <T> Result<T> success(String msg) {
        return of(0,msg,null);
    }

    public static <T> Result<T> success(String msg,T data) {
        return of(0,msg,data);
    }

    public static <T> Result<T> success(T data) {
        return of(0,"处理成功",data);
    }


    public static <T> Result<T> of(Integer code,String msg,T data) {
        return new Result<T>(code,msg,data);
    }

    public static <T> Result<T> fail(String msg) {
        return of(-1, msg, null);
    }

}
